home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ADA Programming Guide
/
ADA Programming Guide.iso
/
ada_pcdp
/
ada
/
ada.doc
next >
Wrap
Text File
|
1996-01-30
|
7KB
|
185 lines
Ada Programs
for
Principles of Concurrent and Distributed Programming
M. Ben-Ari
Prentice-Hall International
1989
1. Introduction
The programs on this diskette are Ada implementations of
concurrent and distributed algorithms. They can be studied
as laboratory exercises or used as a framework for implementing
other algorithms. The programs are written in (standard) Ada
and will run on any (validated) Ada compiler, however,
the implementation of concurrency is not prescribed by
the standard and thus there may be variations in the
behavior of the programs. In any case, the user or
instructor must be familiar with implementation-specific
commands relating to tasking.
The behavior of the programs can be followed by inserting
print statements within the tasks. It is possible to influence
the execution of the programs by changing task priorities
or introducting delay statements. A good on-line debugger
is extremely helpful.
Some of the programs contain infinite loops while others
have limits on the number of cycles that each task will
execute. Be sure that you know how to interrupt a deadlocked
or non-terminating program.
2. VAX Ada
The programs were developed on the VAX Ada compiler under
the VMS operating system. VAX-specific commands used are:
pragma Time_Slice(0.01);
forces maximum time slicing (10 ms)
pragma Volatile(N);
forces every access to global variable N to be
to memory rather than to a register
The file VAX.COM contains compilation and link statements
for all the programs. Before compiling Ada programs,
a library must be created using the command ACS CREATE LIBRARY.
After each login (or as part of a batch command file)
the command ACS SET LIBRARY must be given to direct the
compilations and links to the Ada library.
3. Alsys Ada
The programs were also run under Alsys Ada. The compiler
ignores the VAX-specific pragmas. Alsys Ada recognizes standard
pragma Shared which should be used instead of Volatile though
the programs worked as is. Tasking is enabled by changing
parameters of the Bind command. The following command should
be used to change default parameters (which can be stored
as part of the initialization file):
DEFAULT.FIND(TIMER=>FAST,SLICE=>10).
The file ALSYS.CMD contains compile and bind commands for
all the programs and can be used as a script for the
INVOKE command. A program library must be created and
set before use.
4. List of files
The following is a list of the Ada source files on the disk:
bakery.ada -- Lamport's bakery algorithm
buffer.ada -- Bounded buffer package
defs.ada -- Linda tuple space definitions
defsbody.ada -- Package body of defs.ada
dekker.ada -- Dekker's algorithm
ds.ada -- Dijkstra-Scholten algorithm
first.ada -- First attempted solution of mutual exclusion
fourth.ada -- Fourth attempted solution of mutual exclusion
hard.ada -- Emulation of hardware primitives
incr.ada -- Simultaneously increment of a global integer
matrixl.ada -- Matrix multiplication in Linda
matrixo.ada -- Matrix multiplication in occam
meex.ada -- Mutual exclusion using EXCHANGE
mesem.ada -- Mutual exclusion using semaphore
mets.ada -- Mutual exclusion using TEST-AND-SET
mon.ada -- Monitor implementation
pca.ada -- Producer-consumer in Ada
pcbs.ada -- Producer-consumer with binary semaphore
pcm.ada -- Producer-consumer using monitors
pcmon.ada -- Monitor for producer-consumer
pcs.ada -- Producer consumer with semaphores
peter.ada -- Peterson's algorithm
phil1.ada -- Dining philosophers: first attempt
phila.ada -- Dining philosophers: asymmetric solution
philm.ada -- Dining philosophers: monitor solution
philr.ada -- Dining philosophers: Room semaphore
phmon.ada -- Monitor for dining philosophers
ra.ada -- Ricart-Agrawala algorithm
rw.ada -- Readers and writers
rwmon.ada -- Monitor for readers and writers
second.ada -- Second attempted solution of mutual exclusion
sem.ada -- Semaphore package
snap.ada -- Snapshot algorithm
tasksl.ada -- Tasks for Linda tuple space
taskso.ada -- Tasks for occam matrix multiplication
third.ada -- Third attempted solution of mutual exclusion
tm.ada -- Terminate-with-marking algorithm
tup.ada -- Emulation of Linda tuple space
tupbody.ada -- Package body for tup.ada
workers.ada -- Worker tasks for Linda matrix multiplication
5. Comments on the programs
5.1 Mutual exclusion algorithms
The common memory algorithms depend on time slicing. However,
given the long duration of the 10 ms. slice relative to the
speed of execution of the algorithms, it is difficult, if not
impossible to actually see some of the pathologies.
INCR clearly shows the unpredictability of concurrency and
THIRD does deadlock.
Package HARD simulates hardware primitives EXCHANGE and
TEST-AND-SET.
5.2 Semaphores
Semaphores are implemented using (private) task types.
There are separate types for (general) semaphores and
binary semaphores. Binary semaphores ignore Signal instructions
if the value is 1. All semaphores must be explicitly initialized.
5.3 Producer-Consumer solutions
Producers are given a higher priority than consumers to allow
the buffer to fill up. Occasionally, proceducers are delayed
so that the buffer can be emptied.
5.4 Monitors
The design of the monitor implementation is discussed in the book.
Note that the implementation assumes that every Signal is the
last statement in its procedure.
5.5 Dining philosophers
PHIL1 is supposed to deadlock. PHMON contains two Signals
in a monitor procedure. This causes the program to deadlock
when the finite number of Think-Eat cycles have been completed.
5.6 occam
As discussed in the book, the emulation of occam is not very
transparent because of the mismatch between the symmetric
channel addressing in occam as opposed to the asymmetric task
addressing in Ada. The solution chosen should allow an instructor
familiar with Ada to construct a skeleton for other occam programs
by rewriting Task_Types, Tasks and Channel_Task. Activation and
configuration should also be supplied to the student who could
then write the individual task bodies and experiment with them.
5.7 Linda
The tuple package contains tasks that synchronize access to the
tuple space. Termination of tasks that depend on a library
package is not defined in the standard. The VAX implementation
does terminate the program, but problems have been observed
in the Alsys implementation. The solution would be to
insert the package into the main program MATRIXL so that
the tasks would depend on the main procedure rather than
a library package.
5.8 Distributed algorithms
Even though these algorithms use global variables to communicate
between the various tasks comprising one "node", time slicing
is not required because delay statements have been inserted
to force the scheduler to run as needed.
The Dijkstra-Scholten algorithm does not terminate. After
the source node announces that the system has terminated, the
tasks that look for messages will still run indefinitely and
the program must be manually interrupted.